var express = require('express');
var router = express.Router();
let { UserListmongoose,
  nationModel,
  educationModel,
  maritalModel,
  serveModel,
  cateModel,
  tagModel,
} = require('../../modules/model')

router.get('/user', async (req, res) => {
  let data = await UserM.find()
  res.send({
    code: 200,
    data
  })
})
//信息
router.get('/csclist', async (req, res) => {
  let list=await UserListmongoose.find()
  res.send({
    code: 200,
    data: list
  })
})
//添加信息
router.post('/addlist',async(req,res)=>{
  console.log(req.body);
  let add=req.body
  console.log(add);
  await UserListmongoose.create(add)
  res.send({
    code:200,
    msg:"添加成功"
  })
})
//删除信息

router.delete('/dels',async(req, res) => {
  let id=req.body.id
  await UserListmongoose.deleteOne(id)
  res.send({
    code: 200,
    msg:"删除成功"
  })
})

//民族
router.get('/minzus',async(req, res) => {
  let list=await nationModel.find()
  res.send({
    code: 200,
    data: list
  })
})

//文化程度
router.get('/wenhuas',async(req, res) => {
  let list=await educationModel.find()
  res.send({
    code: 200,
    data: list
  })
})


//婚姻情况
router.get('/hunyins',async(req, res) => {
  let list=await maritalModel.find()
  res.send({
    code: 200,
    data: list
  })
 
})

//全员服务的列表和添加

router.get('/services',async(req, res) => {
  let list=await serveModel.find().populate(["cateId","tagId"])
  res.send({
    code: 200,
    data: list
  })
})

router.post('/addservice',async(req,res)=>{
  let data=req.body
  await serveModel.create(data)
  res.send({
    code:200,
    msg:"添加成功"
  })
})


//服务类型

router.get('/serve/list', async (req, res) => {
  let list = await cateModel.find();
  res.send({
    code: 200,
    data: list
  });
});

//服务标签

router.get('/tag/list', async (req, res) => {
  let list = await tagModel.find();
  res.send({
    code: 200,
    data: list
  });
});

//添加服务

router.post("/seves/add", async (req, res) => {
  let list=req.body
  console.log(list);
  await serveModel.create(list)
  res.send({
    code: 200,
    msg: "添加成功",
  });
});



//删除服务

router.delete('/sevredel',async(req, res) => {
  let id=req.body.id
  await serveModel.deleteOne(id)
  res.send({
    code: 200,
    msg:"删除成功"
  })
})
module.exports = router;
